﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Security;
using System.Security.Cryptography.X509Certificates;

namespace TestWebApplication
{
    public partial class Configure : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            /*X509Certificate2Collection certs = CertStore.getAllCerts();

            foreach (X509Certificate2 cert in certs)
            {
                certificates.Items.Add(new ListItem()
                {
                    Text = cert.GetNameInfo(X509NameType.SimpleName, false),
                    Value = cert.GetNameInfo(X509NameType.SimpleName, false)
                });
                
            }*/

            environment.Items.Add(new ListItem() { Text = "OneBox", Value = "OneBox" });
            environment.Items.Add(new ListItem() { Text = "Int", Value = "Int" });
            environment.Items.Add(new ListItem() { Text = "Production", Value = "Production" });

            APIDownList.Items.Add(new ListItem() { Text = "COMMERCE", Value = "COMMERCE" });
            APIDownList.Items.Add(new ListItem() { Text = "MINT", Value = "MINT" });
            if (String.IsNullOrEmpty(server.Text))
            {
                server.Text = ServiceSettings.ServerUrl;
                password.Text = ServiceSettings.Password;
                address.Text = ServiceSettings.WebsiteAddress;
                connector.Text = ServiceSettings.Connector;
            }
        }

        protected void submit_click(object sender, EventArgs e)
        {
            string serverUrl = server.Text;
            string connectorName = connector.Text;
            string passwords = password.Text;
            string env = environment.SelectedValue;
            string websiteAddress = address.Text;
            string API = APIDownList.Text;

            ServiceSettings.modifySettings(serverUrl, connectorName, passwords, env, websiteAddress, API);
            //ServiceSettings.loadSettings();            
            Response.Redirect(ServiceSettings.Api+"/Login.aspx");
        }
    }
}